<?php

use GuzzleHttp\Client;


// 用户端授权
class Oauth extends M_Controller
{

    // 公众号授权
    public function mpOauth()
    {
        if ((int)$this->uid < 1) {
            apiSuccess(-4001, '请登录');
        }
        try {
            $code = $this->input->get('code');
            if (empty($code)) {
                apiSuccess(0, '参数缺失');
            }
            require_once WEBPATH . 'web/libraries/Wechat/Mp.php';
            $openid = (new Mp($code))->Oauth()['openid'];
            $mp_status = $this->models('member')->wxInfo($this->uid, 'openid');
            if (!isset($mp_status)) {
                $this->models('member')->addOathData($this->uid, $openid);
            }
            apiSuccess(1, 'success');
        } catch (Exception $e) {
            apiSuccess($e->getCode(), $e->getMessage());
        }
    }
}
